from datetime import datetime
from typing import Optional
from uuid import UUID

from pydantic import BaseModel, EmailStr, Field


class UserCredentialDTO(BaseModel):
    """User credential data transfer object."""
    username: str = Field(..., min_length=3, max_length=50)
    password: str = Field(..., min_length=6)


class UserCreateDTO(UserCredentialDTO):
    """User creation data transfer object."""
    email: EmailStr
    is_active: bool = True
    is_superuser: bool = False


class UserUpdateDTO(BaseModel):
    """User update data transfer object."""
    email: Optional[EmailStr] = None
    is_active: Optional[bool] = None
    is_superuser: Optional[bool] = None


class UserDTO(BaseModel):
    """User data transfer object."""
    id: UUID
    username: str
    email: EmailStr
    is_active: bool
    is_superuser: bool
    created_at: datetime
    updated_at: datetime

    class Config:
        from_attributes = True
